﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using ELMWCFServiceClass.ELMWCF;
using ELMApplication.Common.Const;

namespace SettingModule.Views.ELMListConfigView
{
    public partial class CW_ELMListDetial : ChildWindow
    {
        public CW_ELMListDetial(IELMListConfigPresentationModel model)
        {
            InitializeComponent();
            this.model = model;
            this.DataContext = model;

            this.Loaded += new RoutedEventHandler(CW_ELMListDetial_Loaded);
        }

        void CW_ELMListDetial_Loaded(object sender, RoutedEventArgs e)
        {
            switch (model.DetailPrivege)
            {
                case PrivegeTypes.New:
                    cbContenttype.SelectedIndex = -1;
                    
                    break;
                case PrivegeTypes.Edit:
                    cbContenttype.IsEnabled = false;
                    cbContenttype.SelectedIndex = -1;
                   var sel= model.AllContentTypes.First(c=>c.ContentId==model.CurrentData.ContentType.ContentId);
                    int d = model.AllContentTypes.IndexOf(sel);
                    cbContenttype.ItemsSource=model.AllContentTypes;

                    cbContenttype.SelectedIndex = d;
                    
                    // cbDuty.UpdateLayout();
                    break;
            }
        }


        private IELMListConfigPresentationModel model;

        private void OKButton_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = true;
            model.SaveData();
        }

        private void CancelButton_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = false;
             
        }

        private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (e.AddedItems.Count == 1)
            {
                ContentType data = (ContentType)e.AddedItems[0];
                model.CurrentData.ContentType = data;
            }
        }

     

      
    }
}

